//package com.baishancloud.log.Other
//
//import java.io.ByteArrayInputStream
//import java.nio.charset.StandardCharsets
//import java.util.Objects
//import scala.collection.mutable.ListBuffer
//import scala.util.control.Breaks
//
///**
// *
// * @author ziqiang.wang
// * @date 2022/4/7 09:21
// */
//object S3ReadWriteUtil extends Serializable {
//
//  private val endPoint: String = "http://ss.bscstorage.com"
//  private val accessKey: String = "oqi9zsc01d6r873vea24"
//  private val secretKey: String = "trJgQa7ElbATyV1kUwlpJA3T2J67u+R4rhbKED7X"
//  private val bucket: String = "flink-checkpoint"
//
//
//  private val awsCreds = new BasicAWSCredentials(accessKey, secretKey)
//  private val clientConfiguration = new ClientConfiguration()
//  clientConfiguration.setSocketTimeout(60 * 60 * 1000)
//  clientConfiguration.setConnectionTimeout(60 * 60 * 1000)
//  private val s3 = new AmazonS3Client(awsCreds, clientConfiguration)
//  s3.setRegion(Region.getRegion(Regions.US_EAST_1))
//  s3.setEndpoint(endPoint)
//  s3.setS3ClientOptions(S3ClientOptions.builder.setPathStyleAccess(true).disableChunkedEncoding.build)
//
//
//  private val objectMetadata = new ObjectMetadata
//  objectMetadata.setContentType("text/html")
//  //  objectMetadata.addUserMetadata("key-foo", "value_bar")
//
//
//  /**
//   * 将 list 列表中的数据写到指定的文件
//   *
//   * @param list     包含要写出的所有字符串
//   * @param filePath 要写出的目标文件路径
//   */
//  def read(list: ListBuffer[String], filePath: String): Unit = {
//    if (list != null) {
//      // 先删除原始文件
//      s3.deleteObject(bucket, filePath)
//      // 将新内容写入文件
//      for (elem <- list) {
//        val inputStream: ByteArrayInputStream = new ByteArrayInputStream((elem + '\n').getBytes(StandardCharsets.UTF_8))
//        val putObjectRequest: PutObjectRequest = new PutObjectRequest(bucket, filePath, inputStream, objectMetadata)
//        putObjectRequest.setCannedAcl(CannedAccessControlList.PublicReadWrite)
//        s3.putObject(putObjectRequest)
//      }
//    }
//  }
//
//  /**
//   * 读取指定文件中的内容，并将其转化为一行一行的字符串写到指定的 list 列表
//   *
//   * @param list     存放读取到文件的字符串内容
//   * @param filePath 要读取的文件
//   */
//  def write(list: ListBuffer[String], filePath: String): Unit = {
//    val s3Object: S3Object = s3.getObject(bucket, filePath)
//    val readLength: Int = 8192
//    val buffer: Array[Byte] = new Array[Byte](readLength)
//    val inputStream: S3ObjectInputStream = s3Object.getObjectContent
//    val content: StringBuilder = new StringBuilder()
//    while (true) {
//      Breaks.breakable {
//        // 每次读取数据之前，应该先清理一下缓存数组的内容
//        val length: Int = inputStream.read(buffer)
//        if (length < readLength) {
//          if (length > 0) {
//            val bytes: Array[Byte] = new Array[Byte](length)
//            for (index <- 0 until length) {
//              bytes(index) = buffer(index)
//            }
//            content.append(new String(bytes, StandardCharsets.UTF_8))
//            Breaks.break()
//          } else {
//            Breaks.break()
//          }
//        } else {
//          content.append(new String(buffer, StandardCharsets.UTF_8))
//        }
//      }
//    }
//
//    // 对内容一个一个字符进行解析，将其按照换行符分隔，转化为一行一行数据，放到 list 集合
//    val line: StringBuilder = new StringBuilder()
//    for (elem: Char <- content) {
//      if (Objects.equals(elem, '\n')) {
//        list += line.toString()
//        line.delete(0, line.length)
//      } else {
//        line.append(elem)
//      }
//    }
//  }
//
//}
